package web;


import com.hmall.common.PageDTO.PageDTO;
import com.hmall.common.pojo.Item;
import com.hmall.search.doc.ItemDoc;
import com.hmall.search.doc.RequestParams;
import com.hmall.search.service.ISearchService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private ISearchService searchService;

    /**
     * 实现搜索功能
     * @param requestParams 过滤的信息
     * @return
     */
    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody RequestParams requestParams) {
        log.info("[商品功能，分页查询] ItemDoc:{}", requestParams);

        return searchService.list(requestParams);
    }

    /**
     * 过滤项聚合功能
     * @param requestParams 过滤的信息
     * @return
     */
    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody RequestParams requestParams) {
        return searchService.filters(requestParams);
    }


}